
//获取URL传递的参数
function getParm(word){
	  var url=window.location.search;//获取url参数
	  url=url.substr(1,url.length);
	  if(url.indexOf('&')==-1){
	    brr=url.split('=');
			if(brr[0]==word){
			   return brr[1];
			}
	  }else{
	    var arr=url.split('&');
		var brr='';
		for(var i=0;i<arr.length;i++){
			brr=arr[i].split('=');
			if(brr[0]==word){
				return brr[1];
			}
		}	
	   } 
	}
//获取商品详情页的信息
$(function(){  
var ht='';
$.ajax(  
    {   data:{goods_id:goods_id},
        type:'get',  
        url : myconfig['api']+'goods_show',  
        dataType : 'json',  
        jsonp:"jsoncallback",  
        success  : function(data) {  
            if(data.status=1){				
				var money=parseInt(data.lists["goods_price"])+parseInt(data.lists["goods_bonus"]);
				  ht+='<div class="trial_img">';
				  ht+='<img src='+myconfig['url']+data.lists["thumb"]+'>';
				  ht+='<div class="trial_title"><p>'+data.lists["title"]+'</p>&nbsp; <span class="you">包邮</span>';
				  if(data.lists["protype"]==2){
					  ht+='<span class="pai_a_b">送图片商品</span>';
				  }
				  ht+='</div>';
				  ht+='</div>';
				  ht+='<div class="trial_price">试用价<b>￥'+data.lists["goods_price"]+'</b>元<i>（赠送<b>'+data.lists["goods_bonus"]+'</b>元红包）</i></div>';
				  ht+='<div class="trial_num">';
				  ht+='<li>限量份数：<b>'+data.lists["goods_number"]+'</b>份</li>';
				  ht+='<li>剩余份数：<b>'+data.lists["number"]+'</b>份</li>';
				  ht+='<li>申请人数：<b>'+data.lists["apply_people"]+'</b>人</li>';
				  ht+='<li>剩余：<span id="shijian"></span></li>';
				  ht+='<input type="hidden" id="end_time" value='+data.lists['end_time']+'></input>';
				  ht+='<div class="clear"></div>';
				  ht+='</div>';
				  ht+='<div class="trial_bzj">';
				  ht+='<img src="/images/a3.jpg">商家已存入保证金<b>￥'+data.lists["goods_deposit"]+'</b>元，请放心申请！';
				  ht+='</div>';
				  ht+='<div class="trial_lc">';
				  ht+='<h3>试用流程</h3>';
				  ht+='<li>1、申请试用，获得试用资格</li>';
				  ht+='<li>2、按照提示以 <b class="cc">￥'+data.lists["goods_price"]+'</b>元去指定平台购物</li>';
				  ht+='<li>3、回平台填写购买付款的订单号</li>';
				  ht+='<li>4、确认收货-给予评价-填写试用报告</li>';
				  ht+='<li>5、系统返还<b class="cc">'+money+'元</b>到您平台账户中</li>';
				  ht+='<div class="trial_type_img">';
				  
				 if(data.lists['type']=='search'){
					 ht+='<img src="/images/sosuo.png">';
				 }else if(data.lists['type']=='qrcode'){
					 ht+='<img src="/images/saoma.png">';
				 }else if(data.lists['type']=='general'){
					 ht+='<img src="/images/putong.png">';
				 }else if(data.lists['type']=='taokouling'){
					 ht+='<img src="/images/taokouling.png">';
				 }
				 
				 ht+='</div>';
				 ht+='</div>';
				 ht+='<div class="trial_lc">';
				 ht+='<h3>注意事项</h3>';
				 ht+='<li>1.与商家聊天的时候不要提及试用相关信息。</li>';
				 ht+='<li>2.禁止通过淘宝客.返利网等返现网站链接下单。</li>';
				 ht+='<li>3.不要催促商家发货.返款,请遵守平台相关规定。</li>';
				 ht+='</div>';
				 ht+='<div class="trial_lc">';
				 ht+='<h3>温馨提示</h3>';
				 ht+='<li>1.完善个人相关资料，可以提高通过率。</li>';
				 ht+='<li>2.分享活动链接至QQ好友,微信朋友圈,微信好友,邀请他们参与有奖励。</li>';
				 ht+='<li>3.在申请理由里面详细的介绍一下个人的试用经历和心得,更有助提高通过率。</li>';
				 ht+='</div>';
				 ht+='<div class="trial_details">';
				 ht+='<div class="details_tab" >';
				 ht+='<li id="active">活动详情</li>';
				 ht+='<li id="applied">已申请（'+data.lists["apply_people"]+'）</li>';
				 ht+='<li id="report">试用报告（'+data.lists["finish_people"]+'）</li>';
				 ht+='</div>';
				 ht+='<div class="details_body" id="details_body">';
				 ht+='<div class="details_news" id="details_news">';
				 ht+=''+data.lists["goods_content"]+'</p>';
				 ht+='</div>';
	
				 $.ajax(  
					{   data:{goods_id:goods_id,state:1},
						type:'get',  
						url : myconfig['api']+'good_user_list',  
						dataType : 'json',  
						jsonp:"jsoncallback",  
						success  : function(data) {  
							ht+='<div class="details_tx" id="details_tx">';
							for(var i=0;i<data.lists.length;i++){
								ht+='<li>';
								ht+='<div class="details_tx_img">';
								ht+='<img src='+myconfig['url']+data.lists[i].avatar+'>';
								ht+='</div>';
								ht+='<p class="yc">'+data.lists[i].nickname+'</p>';
								ht+='</li>';
							}							
							
									$.ajax(  
										{   data:{goods_id:goods_id},
											type:'get',  
											url : myconfig['api']+'trial_report_lists',  
											dataType : 'json',  
											jsonp:"jsoncallback",  
											success  : function(data) {  
											    ht+='</div><div class="details_report" id="details_report">';
												for(var i=0;i<data.lists.length;i++){
													
													ht+='<li>';
													ht+='<div class="reportL">';
													ht+='<div class="report_tx" >';
													ht+='<img src='+myconfig['url']+data.lists[i].avatar+'>';
													ht+='</div>';
													ht+='<p class="yc">'+data.lists[i].nickname+'</p>';
													ht+='</div>';
													ht+='<div class="reportR">';
													ht+='<p>'+data.lists[i].content+'</p>';
													ht+='<p class="report_img"><img src='+myconfig['url']+data.lists[i].thumb+'></p>';
													ht+='<time>提交时间：<span>'+data.lists[i].inputtime+'</span></time>';
													ht+='</div>';
													ht+='</li>';
												}	
												
 												$('#show_trial').append(ht);
												    //剩余时间的设置
													function mytime(){ 			
													var t=$('#end_time').val()-parseInt(new Date().getTime()/1000);
													if(t<=0){
														$('#shijian').html('您来晚了！下次吧。');
														return;
													}
													//格式化剩余时间
													
														 d=parseInt(t/(3600*24));
														 tim=t-d*(3600*24);
														 h=parseInt(tim/3600);
														 tim=tim-h*3600;
														 mi=parseInt(tim/60);
														 s=tim-mi*60;													
														$('#shijian').html(d+'天'+h+'时'+mi+'分'+s+'秒');														
													}
													//定时执行
													setInterval(mytime,1000);
													
												//点击切换子页
												$(".trial_details").slide({
														titCell:".details_tab li", 
														mainCell:".details_body",
														delayTime:0 
												});
												
													
											},  
											error : function() {  
												alert('获取试用报告数据失败');  
											}  
										}  	
									); 

							
							
									
						},  
						error : function() {  
							alert('获取申请试用用户列表数据失败');  
						}  
					}  	
				);
				
			 } 			
        },  
        error : function() {  
            alert('获取商品信息数据失败');  
        }  
    }  
); 

//点击“免费申请”
$(".apply_trial").click(function(){
	 //如果没有登录信息
	if(!(myinfo['userid'] && myinfo['random'])){
		location.href='../user/login.html';
	}
     //获取用户的绑定淘宝信息
    $.ajax({  
			    data:{userid:myinfo['userid'],random:myinfo['random']},
				type:'post',  
				url : myconfig['api']+'get_tbaccount',  
				dataType : 'json',  
				jsonp:"jsoncallback",  
				success  : function(data) {  
					if(data.status==1){
						var htms='选择账号';
						htms+='<select id="account">';
						for(var i=0;i<data.lists.length;i++){
							htms+='<option value='+data.lists[i].id+'>'+data.lists[i].account+'</option>';
						}
						$('.popup-head').empty();
						$('.popup-head').append(htms);
						
                        //点击提交申请试用	
					    $(".input_yes").click(function(){
						  var talk=$("#talk").val();
						  var bind_id=$('#account').val();						 
							//提交试用申请        
							$.ajax({    data:{userid:myinfo['userid'],talk:talk,goods_id:goods_id,bind_id:bind_id},
										type:'post',  
										url : myconfig['api']+'pay_submit',  
										dataType : 'json',  
										jsonp:"jsoncallback",  
										success  : function(data) {  
											if(data.status==0){
												 art.dialog({
								                    lock: true,
								                    fixed: true,
								                    icon: 'face-sad',
								                    title: '错误提示',
								                    content: data.msg,
								                    ok: true,
								                 });

											}else{
												art.dialog({
								                    lock: true,
								                    fixed: true,
								                    icon: 'face-smile',
								                    title: '提示',
								                    content: data.msg,
								                    ok: true,
								                });
                                                
											}

											$(".popup").fadeOut();//弹窗淡出
													
										},  
										error : function() {  
												art.dialog({
								                    lock: true,
								                    fixed: true,
								                    icon: 'face-sad',
								                    title: '错误提示',
								                    content: '获取权限失败',
								                    ok: true,
							                    }); 

										} 

							});

						});

					}

				},  
				error : function() {  	
                //失败的信息
				}  
			
	}); 

})





})

